<script setup lang="ts">
import DoctorCard from './DoctorCard.vue'
import { useWindowSize } from '@vueuse/core'
import type { DoctorList, PageParams } from '@/types/consult'
import { ref, onMounted } from 'vue'
import { getDoctorPage } from '@/services/consult'

const { width } = useWindowSize()
// 数据列表
const list = ref<DoctorList>([])
// 查询参数
const pageParams = ref<PageParams>({
  current: 1,
  pageSize: 5
})
const loadData = async () => {
  const res = await getDoctorPage(pageParams.value)
  list.value = res.data.rows
  if (res.data.rows.length === 0) {
    // 接口数据暂时为空，添加模拟数据
    for (let i = 0; i < 5; i++) {
      list.value.push({
        id: '001',
        name: '是三好',
        avatar:
          'https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/consult/deafaultAvatar.jpg',
        hospitalName: '中山大学肿瘤防治中心',
        gradeName: '三级甲等',
        depName: '胃肠外科',
        positionalTitles: '副主任医师',
        likeFlag: 0,
        serviceFee: 200,
        consultationNum: 120,
        score: 5,
        major: '肿瘤防治'
      })
    }
  }
}
onMounted(() => loadData())
</script>

<template>
  <div class="follow-doctor">
    <div className="head">
      <p>推荐关注</p>
      <a href="javascript:;"> 查看更多<i class="van-icon van-icon-arrow" /></a>
    </div>
    <div class="body">
      <!-- swipe 组件 -->
      <!-- 在 375 宽度设备，滚动宽度为 150 -->
      <!-- 在其他设备需要等比例设置滚动的宽度 -->
      <!-- 150 / 375 =  scrollWidth / deviceWidth-->
      <!-- scrollWidth = 150 / 375 * deviceWidth 就可以适配 -->
      <van-swipe
        :width="(150 / 375) * width"
        :show-indicators="false"
        :loop="false"
        v-if="list.length > 0"
      >
        <van-swipe-item v-for="item in list" :key="item.id">
          <doctor-card :item="item" />
        </van-swipe-item>
      </van-swipe>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.follow-doctor {
  background-color: var(--cp-bg);
  height: 250px;

  .head {
    display: flex;
    justify-content: space-between;
    height: 45px;
    align-items: center;
    padding: 0 15px;
    font-size: 13px;

    > a {
      color: var(--cp-tip);
    }
  }

  .body {
    width: 100%;
    overflow: hidden;
  }
}
</style>
